package com.aaa.member.controller;

import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.member.entity.tbAccountStatement;
import com.aaa.member.service.tbAccountStatementService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ( tbAccountStatement)表控制层
 *
 * @author makejava
 * @since 2020-11-18 08:54:33
 */
@RestController
@RequestMapping(" tbAccountStatement")
public class tbAccountStatementController {
    /**
     * 服务对象
     */
    @Resource
    private tbAccountStatementService tbAccountStatementService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public tbAccountStatement selectOne(Integer id) {
        return this.tbAccountStatementService.queryById(id);
    }

    /**
     * 用户充值时，会增加积分
     * @param tbAccountStatement
     * @return
     */
    @GetMapping("Addmount")
    public Result Addmount(tbAccountStatement tbAccountStatement){
        System.out.println(tbAccountStatement.getAccount()+" "+tbAccountStatement.getPaytype());
        return tbAccountStatementService .insert(tbAccountStatement);
    }
    /**
     * 查询账单的数据
     * @param tbAccountStatement
     * @return
     */
    @PostMapping("queryAccountStatementByDynamic")
    public Result queryAccountStatementByDynamic (@RequestBody tbAccountStatement tbAccountStatement){
        return tbAccountStatementService.queryAllByDynamic(tbAccountStatement);
    }

    /**
     * 进行充值
     * @param accountStatement
     * @return
     */
    @PostMapping("addmoney")
    public Result addmoney(@RequestBody tbAccountStatement accountStatement) {

        return tbAccountStatementService.addAccBlance (accountStatement);
    }

    /**
     * 通过客户id查询相关明细信息
     * @return
     */
    @GetMapping("selectByClientId")
    public Result selectByClientId(Integer tbMember) {
        return new Result(ReturnCode.SUCCESSS.getCode (), ReturnCode.SUCCESSS.getMsg (),
                tbAccountStatementService.selectByTbMemberId (tbMember));
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @GetMapping("selectAll")
    public List<tbAccountStatement> queryAllByLimit(int offset, int limit) {
        return this.tbAccountStatementService.queryAllByLimit (offset, limit);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public boolean deleteById(Integer id) {
        return this.tbAccountStatementService.deleteById (id);
    }

}